import csv
import os


def reversecsv(name):
    path = os.getcwd()
    with open(path + '/data/' + name + '.csv', encoding='gbk')as f:
        f_csv = csv.DictReader(f)
        a = [i for i in f_csv]
    a.reverse()
    headers = ['日期', '股票代码', '名称', '收盘价', '最高价', '最低价']
    with open(name + 'rev.csv', 'w', newline='', encoding='utf-8')as f:
        f_csv = csv.DictWriter(f, headers)
        f_csv.writeheader()
        f_csv.writerows(a)


if __name__ == '__main__':
    reversecsv('688317')
